package Zoo.Handler;


/*
 *  重要！！（配套Loginview）
 * */



import Zoo.Entity.ZoomenEntity;
import Zoo.Impl.ZoomenServiceImpl;
import Zoo.Service.ZoomenService;
import Zoo.View.LeaderView.AddZoomenView;
import Zoo.View.LeaderView.LeaderView1;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class AddZoomenViewHandler implements ActionListener {
    private AddZoomenView addZoomenView;
    private LeaderView1 leaderView1;

    public AddZoomenViewHandler(AddZoomenView addZoomenView, LeaderView1 leaderView1){
        this.addZoomenView=addZoomenView;
        this.leaderView1=leaderView1;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        JButton jButton=(JButton) e.getSource();
        String text =jButton.getText();
        if("添加".equals(text)){
            ZoomenService zoomenService=new ZoomenServiceImpl();
            ZoomenEntity zoomenEntity =addZoomenView.buildZoomenEntity();
            boolean addResult=zoomenService.add(zoomenEntity);
            if(addResult){
                //重新加载表格查到最新数据
                leaderView1.reloadTable();
                addZoomenView.dispose();
            }else{
                JOptionPane.showMessageDialog(addZoomenView,"添加失败");

            }

        }
    }

}
